package com.abocode.aichat.server.modules.handler;

import com.abocode.aichat.data.*;
import com.abocode.aichat.server.context.channel.ChannelWrapper;
import com.abocode.aichat.server.context.ServerRuntimeContext;
import com.abocode.aichat.server.modules.ModuleServiceHandler;
import com.abocode.aichat.server.context.delivery.reply.Replies;
import com.alibaba.fastjson.JSON;

/**
 * @author guanxf
 */
public class ChatConfirmServiceHandler implements ModuleServiceHandler {
    @Override
    public Replies execute(ChannelWrapper channelWrapper, MessageStanza stanza, ServerRuntimeContext serverRuntimeContext) {
        MessageIdMessageBody body = JSON.parseObject(stanza.body().toString(),MessageIdMessageBody.class);
        if (serverRuntimeContext.getMessagePipeline() == null) {
            throw new NullPointerException("confirm pipeline is null");
        }
        String jid = body.getJid();
        Entity entity = EntityImpl.parse(jid);
        serverRuntimeContext.getMessagePipeline().confirm(entity,body.getMsgId());
        return null;
    }

    @Override
    public ModuleServiceType moduleServiceType() {
        return ModuleServiceType.confirm;
    }
}
